#include "TestPlugin1.h"
#include <thread>
#include <QVector>
#include <QApplication>
#include "Common.h"

TestPlugin1::TestPlugin1(QObject *parent) :
    BasePlugin(MAINWIN_PLUGIN_NAME,
               MAINWIN_PLUGIN_DESCRIPTION)
{
    AddType(User);
    AddType(LeftWidget);
    AddType(QuickWidget);

    mWidget = new QQuickWidget;
}

TestPlugin1::~TestPlugin1()
{

}

void TestPlugin1::OnLoad(int argc, char **argv)
{
//    std::thread t1([](){
//        int count = 0;
//        while(1){
//            count++;
//            QVector<int>* v;
//            SharedInstance->GetMemWriteLock("v1",(void**)&v);
//            v->push_back(count);
//            SharedInstance->UnlockMem("v1");
//            std::this_thread::sleep_for(std::chrono::microseconds(20));
//        }

//    });
    mWidget->setSource(QUrl("qrc:/main.qml"));
//    t1.detach();
    //mWidget->show();

}

void TestPlugin1::AfterLoad()
{
    //mWidget->setSource(QUrl("qrc:/main.qml"));
}

QWidget *TestPlugin1::GetWidget()
{
    if(mWidget->status() == QQuickWidget::Ready){
        return mWidget;
    }else{
        return nullptr;
    }



}
